package proyecto.web;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import proyecto.excepcion.DAOExcepcion;
import proyecto.excepcion.LoginExcepcion;
import proyecto.modelo.Laboratorista;
import proyecto.service.LaboratoristaService;

public class LaboratoristasController extends MultiActionController {

    private LaboratoristaService laboratoristaService;

    public LaboratoristaService getLaboratoristaService() {
        return laboratoristaService;
    }

    public void setLaboratoristaService(LaboratoristaService laboratoristaService) {
        this.laboratoristaService = laboratoristaService;
    }

   public ModelAndView validar(HttpServletRequest request, HttpServletResponse response) {
        String login = request.getParameter("txtlogin");
        String password = request.getParameter("txtpassword");
        try {
            Laboratorista vo = laboratoristaService.validar(login, password);

            System.out.println("EL VO: " + vo);
            HttpSession session = request.getSession();
            session.setAttribute("LABORATORISTA_ACTUAL", vo);
            
        } catch (DAOExcepcion ex) {
            System.out.print("AQUI HAGO EL DAO EXCEPTION");
            System.err.println(ex.toString());
            return new ModelAndView("intranet_laboratoristas/laboratoristas_login");
        } catch (LoginExcepcion ex) {
            System.out.print("AQUI HAGO EL LOGIN EXCEPTION");
            System.out.println(ex.toString());
            return new ModelAndView("intranet_laboratoristas/laboratoristas_login");
        }
        return new ModelAndView("intranet_laboratoristas/laboratoristas_principal");
    }

   public ModelAndView menu_laboratoristas(HttpServletRequest request, HttpServletResponse response) {
        return new ModelAndView("intranet_laboratoristas/laboratoristas_principal");
    }
    
}
